package hbaseclipse.perspectives;

import hbaseclipse.Activator;

import org.eclipse.ui.IFolderLayout;
import org.eclipse.ui.IPageLayout;
import org.eclipse.ui.IPerspectiveFactory;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.WorkbenchException;

public class HbaseClipsePerspective implements IPerspectiveFactory {

    public static final String ID = "hbaseclipse.perspectives.HbaseClipsePerspective";

    @Override
    public void createInitialLayout(IPageLayout layout) {
        defineDefaultLayout(layout);
    }

    private void defineDefaultLayout(IPageLayout layout) {
        String editorArea = layout.getEditorArea();
        IFolderLayout bottom = layout.createFolder("bottom", 4, 0.7F, editorArea);
        bottom.addView("hbaseclipse.views.scan.ScanView");
        bottom.addView("hbaseclipse.views.get.GetView");
        bottom.addView("org.eclipse.ui.console.ConsoleView");
        bottom.addPlaceholder("org.eclipse.ui.views.ProblemView");
        bottom.addPlaceholder("org.eclipse.ui.views.ProgressView");
        bottom.addPlaceholder("org.eclipse.search.ui.views.SearchView");

        IFolderLayout folder = layout.createFolder("topLeft", 1, 0.25F, editorArea);

        folder.addView("org.eclipse.jdt.ui.PackageExplorer");
        folder.addView("org.eclipse.ui.navigator.ProjectExplorer");

        layout.addView("org.eclipse.ui.views.ContentOutline", 2, 0.75F, editorArea);
        layout.addActionSet("org.eclipse.debug.ui.launchActionSet");
        layout.addActionSet("org.eclipse.ui.NavigateActionSet");
    }

    public static void showPerspective() {
        IWorkbench workbench = Activator.getDefault().getWorkbench();
        IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
        if (window != null) {
            try {
                workbench.showPerspective("com.alibaba.itu.tala.ui.perspective", window);
            } catch (WorkbenchException e) {
                e.printStackTrace();
            }
        }
    }
}
